<?php
namespace Api\Controller;

class NewsController extends ApiController {
    
    public function getList() {
        $isHot = I('post.isHot', null);
        $type = I('post.type', null);
        $page = I('post.page', 1);
        $pagesize = I('post.pagesize', 10);
        $filters = array();
        $offset = ($page-1) * $pagesize;
        
        if ($type == 'local') {
            $city = getCity();
            $city_id = M('hat_city')->where(array('city'=>$city))->getField('city_id');
            empty($city_id) || $filters['city_id'] = array('eq', $city_id);
            $filters['country'] = 0;
        } elseif ($type == 'domestic') {
            $filters['country'] = 0;
        } elseif ($type == 'international') {
            $filters['country'] = 1;
        }
        
        if ($isHot != null) {
            $filters['is_hot'] = $isHot == 1 ? 1 : 0;
        }
        
        $result['total'] = M('news')->where($filters)->count() | 0;
        $result['result'] = M('news')->where($filters)->limit($offset,$pagesize)->order('id DESC')->select();
        
        response(1, $result);
    }
    
    public function getDetail() {
        $id = I('post.id', 0);
        $info = M('news')->find($id);
        $info || response(-1, null, '参数有误');
        response(1, $info);
    }
}
?>